package com.qfedu.dao;

import com.qfedu.model.Subitem;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface SubitemDao {
    //根据pid查询
    @Select("select * from Subitem where status=1 and pid = #{pid}")
    List<Subitem> findByPid(int pid);

    //根据suid查询
    @Select("select * from subitem where suid = #{suid}")
    List<Subitem> findBySuid(String suid);

    //添加
    @Insert("insert into subitem (sname,starttime,endtime,pid,updatetime,status) values(" +
            "#{sname},#{starttime},#{endtime},#{pid},#{updatetime},#{status})")
    void addSubitem(Subitem subitem);

    //删除
    @Update("update subitem set status = 0 where suid = #{suid}")
    void deleteSubitem(String suid);

    //修改
    @Update("update subitem set sname=#{sname},starttime=#{starttime},endtime=#{endtime}," +
            "pid=#{pid},updatetime=#{updatetime},status=#{status} where suid = #{suid}")
    void updateSubitem(Subitem subitem);

    //查询所有
    @Results(id = "findAllMap",value = {
            @Result(column = "suid",property = "suid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "pid",property = "project",
                    one = @One(select = "com.qf.dao.ProjectDao.findByPid",fetchType = FetchType.EAGER)),
            @Result(column = "suid",property = "items",
                    one = @One(select = "com.qf.dao.ItemDao.findBySuid",fetchType = FetchType.EAGER))
    })
    @Select("select * from subitem where status = 1")
    List<Subitem> findAll();
}